﻿@using RielAp.Translation;
@using RielAp.Domain.Models;
@model CabinetModel

@{
    ViewBag.Title = Translation.CabinetTitlePage;
    ViewBag.HasNote = true;
    ViewBag.CurrentPage = ViewBag.IsMyCabinet ? NavigationPage.Cabinet : NavigationPage.None;
    string type = "Apartment";
}

<h2>@ViewBag.Title</h2>

<div class="row-fluid">
    @if (TempData["message"] != null)
    {
        <div class="alert alert-error">@TempData["message"]</div>
    }
</div>

<div class="row-fluid">
    <div class="span3">
        <ul class="nav nav-tabs nav-stacked" id="navTabs">
            <li class="@(ViewBag.CabinetCurrentTab == CabinetViewType.Announcements ? "active" : "")"><a href="#" data-target="#announcements">@Translation.CabinetAnnouncementsListTitle</a></li>
            <li class="@(ViewBag.CabinetCurrentTab == CabinetViewType.Feedbacks ? "active" : "")"><a href="#" data-target="#feedbacks">@Translation.CabinetFeedbacksListTitle</a></li>
        </ul>
    </div>
    <div class="span9">
        <div class="tab-content" style="overflow: hidden;">
            <div class="tab-pane @(ViewBag.CabinetCurrentTab == CabinetViewType.Announcements ? "active" : "")" id="announcements" >
                @if (ViewBag.IsMyCabinet)
                {
                    <div class="btn-group" style="margin: 10px 7px 10px 7px;">
                        <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
                            @Translation.CabinetAddAnnouncement
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li>@Html.ActionLink(Translation.CabinetAddApartmentLabel, "AddApartment")</li>
                            <li>@Html.ActionLink(Translation.CabinetAddLandLabel, "AddLand")</li>
                            <li>@Html.ActionLink(Translation.CabinetAddHouseLabel, "AddHouse")</li>
                        </ul>
                    </div>
                }

                @if(Model.Announcements.Count()>0){
                <table class="table">
                    @foreach (var item in Model.Announcements)
                    {
                        <tr>
                            @{
                        ApartmentAnnouncement ap = item as ApartmentAnnouncement;

                        if (ap != null)
                        {
                                @Html.Partial("_Apartment", ap);
                        }
                        else
                        {
                            HouseAnnouncement h = item as HouseAnnouncement;
                            if (h != null)
                            {
                                type = "House";
                                @Html.Partial("_House", h);
                            }
                            else
                            {
                                LandAnnouncement l = item as LandAnnouncement;
                                if (l != null)
                                {
                                    type = "Land";
                                @Html.Partial("_Land", l);
                                }
                            }
                        }
                            }

                            <td style="width: 100px">
                                <div class="btn-group btn-group-vertical">
                                    @if (ViewBag.IsMyCabinet)
                                    {
                                        @Html.ActionLink("Редагувати", "Edit" + type, new { id = item.AnnouncementID }, new { @class = "btn" })
                                        @Html.ActionLink("Стерти", "DeleteAnnouncement", new { id = item.AnnouncementID }, new { @class = "btn" })
                                    }
                                    @Html.ActionLink("Деталі", type + "Details", "Announcements", new { id = item.AnnouncementID }, new { @class = "btn" })
                                </div>
                            </td>

                        </tr>
                    }
                </table>
                }
                else{
                    <div style="width: 100%; display: block; text-align:center; font-size: 22px; font-style: italic; color: #777;">
                        @RielAp.Translation.Translation.CabinetNoAnnouncementsInUser
                    </div>
                }

            </div>
            <div class="tab-pane @(ViewBag.CabinetCurrentTab == CabinetViewType.Feedbacks ? "active" : "")" id="feedbacks">
                @Html.ActionLink(Translation.CabinetAddFeedbackLabel, "AddFeedback", new { phone=Model.UserPhone}, new {@class="btn btn-primary", style="margin: 10px 7px 10px 7px;" })
                @if(Model.Feedbacks.Count()>0){
                <table class="table">
                    @foreach (var item in Model.Feedbacks)
                    {
                        @Html.Partial("_Feedback", item)
                    }        
                </table>
                }
                else{
                    <div style="width: 100%; display: block; text-align:center; font-size: 22px; font-style: italic; color: #777;">
                        @RielAp.Translation.Translation.CabinetNoFeedbacksInUser
                    </div>
                }
            </div>
        </div>

    </div>
</div>

@section scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#navTabs a').click(function (e) {
                e.preventDefault();
                $(this).tab('show');
            })
        });

    </script>
}

